<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




<div style="padding:0;" class="content tabbed">

	<div id="wiz_create">
		<div class="box no-border">
			<div class="header">
				<h3 class="box-title">事件信息</h3>
				<isperp:help id="help2">
					<p>1、请输入事件信息，包括事件标题和事件描述，事件标题为该事件的关键字；</p>
					<p>2、判断当前事件是否属于合同服务范围：</p>
					<p>
						&nbsp;&nbsp;&nbsp;&nbsp;2.1、事件内容是否在服务范围之内。系统根据事件标题自动匹配项目合同关联的服务目录，单击“显示全部”可以查看所有服务目录，若能匹配，请选择并点击“下一步”，否则拒绝提供服务；</p>
					<p>&nbsp;&nbsp;&nbsp;&nbsp;2.2、关联资产是否在合同范围之内。根据客户提供的资产编号，查找该资产是否在服务合同范围之内，系统默认带出该客户的资产；</p>
					<p>3、如果有匹配的服务目录，请选择，并点击“下一步”；如无法匹配，则告知用户不在服务范围，不予受理。</p>
				</isperp:help>

				<c:if test="${not empty caller }">
					<h2 style="padding:10px;">
						&nbsp;&nbsp;来电号码：<label id="caller" style="color:red	">${caller}</label>
					</h2>
				</c:if>
			</div>

			<form:form commandName="model" cssClass="validate" id="incidentForm"
				action="incident/incident/save">
				<form:hidden path="id" />

				<div style="position: relative;height: 100%">
					<div style="position: relative;width:60%;"><jsp:include
							page="step1.jsp"></jsp:include><jsp:include page="step2.jsp"></jsp:include>
					</div>

					<div class="box"
						style="position: absolute;right:5px;top:2px;width:36%"><jsp:include
							page="step6.jsp"></jsp:include></div>

					<div style="position: relative;clear: both">

						<div id="subway_dealdiv" style="display:none">
							<jsp:include page="step4.jsp"></jsp:include>

							<jsp:include page="step5.jsp"></jsp:include>

						</div>
					</div>
				</div>
			</form:form>

		</div>
		<script type="text/javascript">
			function formatSrcName(rowObject) {
				return "<a href=\"javascript:isperp.openDialog({contentUrl:'serviceCatalog/service/view?id="
						+ rowObject.id + "'});\">" + rowObject.name + "</a>";
			}

			function setServiceCatalogValue(id, name) {

				srcServiceGridSelected(id, name);
				$("#projectServiceDialog").wijdialog("close");
			}

			var reselectService = function() {
				$("#selectSrcServiceGrid").show();
				$("#serviceCategoryMsg").html("");
				$("#serviceCategoryId").val("");
				$("#icdIncidentServiceCatalog").html("");
			};

			function projectServiceCategory_Onclick() {
				isperp.openDialog({
					id : "projectServiceDialog",
					onThisWindow : true,
					title : "选择服务目录",
					windowSize : "normal",
					contentUrl : "serviceCatalog/service/selectEdit?projectId="
							+ $("#incidentProjectId").val(),
					buttons : [{
						text : "确定",
						"class" : "nui-mainbtn",
						click : function() {
							var $me = $(this);
							$me.find("iframe")[0].contentWindow.getSelectRow();
						}
					}, {
						text : "关闭",
						"class" : 'grey',
						click : function() {
							$(this).wijdialog("close");
						}
					}]
				});

			}
		</script>

	</div>



</div>

<div class="header">
	<h3>关联流程</h3>
</div>
<isperp:processRelation businessKey="${detail.id }" readonly="false"
	processKey="problemProcess" projectIdControl="projectId">
</isperp:processRelation>
<isperp:buttonList>

	<isperp:processButtons processKey="incidentProcess"
		beforeSubmit="function c(){return beforeSubmit();}"
		processId="${model.processId }" businessKey="${model.id }"
		formId="incidentForm"></isperp:processButtons>
</isperp:buttonList>
<script type="text/javascript">
	function beforeSubmit() {
		//保存扩展属性
		// saveProperty();
		return true;
	}

	function openChoseNextStepUserWindow() {
		var val = $('input:radio[name="dealType"]:checked').val();
		result = $("#incidentForm").valid();
		if (!result)
			return false;
		if ($("#priorityName").val() == "一级" || val == '1') {
			$("#sbBtn").hide();
			$("[data-name='提交']").click();
		} else {
			var categoryId = $("#icdCategoryId").val();
			isperp
					.openDialog({
						id : "nextStepUserDialog",
						onThisWindow : true,
						contentUrl : 'workflow/processRun/beginSubEdit?categoryId=incident',
						title : "选择处理人",
						width : 600,
						height : 520,
						buttons : [
								{
									text : "提交",
									"class" : 'nui-mainbtn',
									click : function() {
										var winObj = $("#nextStepUserDialog")
												.find("iframe")[0].contentWindow;
										var userName = winObj
												.getSelectedValue();
										var suggestion = winObj.document
												.getElementById("suggestion").value;

										if (userName == ""
												|| userName == undefined) {
											isperp.alert("请选择下一步处理人！");
											return false;
										} else {
											$("#supporterId").val(userName);
										}
										$(this).wijdialog("close");
										$("#sbBtn").hide();
										$("[data-name='提交']").attr(
												"data-suggestion", suggestion);
										$("[data-name='提交']").click();
										//$(this).wijdialog("close");
									}
								}, {
									text : "关闭",
									"class" : 'grey',
									click : function() {
										$(this).wijdialog("close");
									}
								}]
					});
		}
		return false;
	}

	//事件标题变化时，自动匹配服务目录
	$("#incidentTitle,#incidentProjectId").change(function() {

		var title = $("#incidentTitle").val();
		var projectId = $("#incidentProjectId").val();

		searchHelpInfo(projectId, title);
	});

	var reselectService = function() {

		$("#selectSrcServiceGrid").show();
		$("#serviceCategoryMsg").html("");
		$("#serviceCategoryId").val("");
		$("#icdIncidentServiceCatalog").html("");
	};

	var assetSelected = function() {

		var selectedRow = assAssectGrid.getRowData();
		if (selectedRow && selectedRow.name) {

			var htmlname = "<a href=\"javascript:isperp.openDialog({contentUrl:'configuration/ci/edit?id="
					+ selectedRow.id + "'});\">" + selectedRow.name + "</a>";

			var msg = htmlname
					+ "  <a href='javascript:void(0)' style='color:blue;padding-left:5px' onclick='reselectAsset();'>[修改]</a>";

			$("#selectAssectGridGrid").hide();
			$("#assAssetId").val(selectedRow.id);
			$("#ciIdMsg").html(msg);

			$("#icdIncidentAssets").html(selectedRow.name);
		}
	};

	var reselectAsset = function() {

		$("#selectAssectGridGrid").show();
		$("#ciIdMsg").html("");
		$("#assAssetId").val("");
		$("#icdIncidentAssets").html("");

	};
	function submitIncident(status) {

		if ($("#serviceCategoryId").val() == "") {
			isperp.alert("请选择服务目录！");
			return false;
		}
		isperp.showLoading({
			onThisWindow : true
		});
		$("#incidentForm").attr("action", "incident/incident/saveAndStart");
		var res = isperp.submitForm({
			formId : "incidentForm",
			data : {
				"type" : status
			},
			success : function(responseText) {
				self.location = responseText.data + "?id=${model.id}";
			}
		});
		if (!res) {
			isperp.hideLoading({
				onThisWindow : true
			});
		}
	}

	//改变处理方式
	//改变处理方式
	function changesway(v) {

		if (v == "1") {
			$("#subway_dealdiv").show();
			$("#subway_dealdiv").find("input").attr("disabled", false);
			$("#subway_dealdiv").find("select").attr("disabled", false);
			$("#subway_dealdiv").find("textarea").attr("disabled", false);
			$("#subway_dealdiv").find("select").trigger("chosen:updated");

			$("#supporter_tr2line").hide();
			$("#supporter_tr2line").find("input").attr("disabled", 'disabled');
			$("#projectMemberGrid_div").hide();

			$("#reject_tr").hide();
			$("#reject_tr").find("textarea").attr('disabled', 'disabled');
			
			if(document.getElementById("confCiMemo").scrollHeight)
				$("#confCiMemo").height(document.getElementById("confCiMemo").scrollHeight);

		} else if (v == "2") {
			$("#subway_dealdiv").hide();
			$("#subway_dealdiv").find("input").attr('disabled', 'disabled');
			$("#subway_dealdiv").find("select").attr('disabled', 'disabled');
			$("#subway_dealdiv").find("textarea").attr('disabled', 'disabled');
			$("#projectMemberGrid_div").show();

			$("#supporter_tr2line").show();
			$("#supporter_tr2line").find("input").attr("disabled", false);

			$("#reject_tr").hide();
			$("#reject_tr").find("textarea").attr('disabled', 'disabled');

		} else {
			$("#subway_dealdiv").hide();
			$("#subway_dealdiv").find("input").attr("disabled", false);
			$("#subway_dealdiv").find("select").attr("disabled", false);
			$("#subway_dealdiv").find("textarea").attr("disabled", false);

			$("#projectMemberGrid_div").hide();

			$("#supporter_tr2line").hide();
			$("#supporter_tr2line").find("input").attr("disabled", false);
			$("#reject_tr").show();
			$("#reject_tr").find("textarea").attr('disabled', false);

		}
	}

	$(document).ready(function() {
		var modelEdit = "${modelEdit}";

		if (modelEdit != "true") {
			$("#urgencyName").val("一般");
			$("#urgencyName").trigger("chosen:updated");
			$("#effectName").val("个人");
			$("#effectName").trigger("chosen:updated");

			$("#dealType_2").click();
		} else {
			var subway = "${model.dealType}";
			if (subway == "")
				subway = 2;
			$("#dealType_" + subway).click();
			changesway(subway);
		}

	});
</script>
<c:if test="${not empty model.cusUserId}">
	<script type="text/javascript">
		setCusUser("${model.cusUserId}");
	</script>
</c:if>
<c:if test="${modelEdit eq true }">


	<script type="text/javascript">
		if ("${model.serviceCategoryId}" && "${model.serviceCategoryId}" != "") {
			srcServiceGridSelected("${model.serviceCategoryId}",
					"${serviceCategoryName}");
		}
		searchHelpInfo("${model.projectId}", "${model.title}");
	</script>

	<script type="text/javascript">
	if(assAssectGrid)
	{
	   assAssectGrid.jqGrid
				.setGridParam({
					url : "configuration/ci/listByCusUserId?cusUserId=${model.cusUserId}"
				});
	}
		
	</script>

</c:if>